<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>报价维护</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/css/oksub.css">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form ok-form" lay-filter="filter">

        <input type="hidden" name="offerId" >
        <div class="layui-form-item">
            <label class="layui-form-label">报价名称</label>
            <div class="layui-input-block">
                <input type="text" name="offerName" placeholder="请输入报价名称" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">寄件区间</label>
            <div class="layui-input-block">
                <select name="sendAreaId" class="layui-select" lay-filter="sendAreaId" lay-verify="required" lay-search="true" >
                    <option value="">请选择寄件区间</option>
                    <option   th:each="s:${send}" th:value="${s.id}"  th:text="${s.rangeName}" />
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">目的区间</label>
            <div class="layui-input-block">
                <select name="destinationAreaId" class="layui-select" lay-filter="destinationAreaId" lay-verify="required" lay-search="true" >
                    <option value="">请选择寄件区间</option>
                    <option  th:each="d:${destination}" th:value="${d.id}"  th:text="${d.rangeName}" />
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">生效时间</label>
            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                <input type="text" name="birthTime" placeholder="请选择生效时间" class="layui-input" id="birthTime">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">失效时间</label>
            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                <input type="text" name="deadTime" placeholder="请选择失效时间" class="layui-input" id="deadTime">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户类型</label>
            <div class="layui-input-block">
                <select name="clientType" class="layui-select" lay-filter="clientType" lay-verify="required" lay-search="true" >
                    <option value="">请选择客户类型</option>
                    <option th:text="结算报价"></option>
                    <option th:text="客户报价"></option>
                    </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="handle">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>
<script type="text/javascript" th:inline="javascript">
    var initData;

    function initForm(data) {
        var jsonString = JSON.stringify(data);
        initData = JSON.parse(jsonString);
    }

    layui.use(["element", "form", "okLayer", "okUtils","laydate","jquery"], function () {
        var form = layui.form;
        var okLayer = layui.okLayer;
        var okUtils = layui.okUtils;
        var laydate = layui.laydate;
        var $ = layui.jquery;
        okLoading.close();
        form.val("filter", initData);

        laydate.render({
            elem: '#deadTime',
            type: 'datetime',
            trigger: 'click',
        });
        laydate.render({
            elem: '#birthTime',
            type: 'datetime',
            trigger: 'click',
        });
        if(initData != null) {
            // 选中下拉框中的值
            $().ready(function () {
                var single = [[${clientType}]];
                $("#clientType option[text= " + single + "]").prop("selected", true);
            });
            $().ready(function () {
                var single = [[${sendingRangeName}]];
                $("#sendAreaId option[text= " + single + "]").prop("selected", true);
            });
            $().ready(function () {
                var single = [[${destinationRangeName}]];
                $("#destinationAreaId option[text= " + single + "]").prop("selected", true);
            });

        }

        form.on("submit(handle)", function (data) {

            okUtils.ajax("/api/quote/handle", "post", data.field, true).done(function (response) {
                console.log(response);
                okLayer.greenTickMsg("提交成功", function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    })
</script>
</body>
</html>
